/**
 * Copyright  2025, Hai Yue Xing He Technology Co., Ltd
 * 
 * @author        ZHAO LIMIN
 * @version       1.0.1
 * @since         2025-04
 * 
 * HYXHCircle     圆形
 * 基于3D，兼顾2D
 */
import { Vec3 } from "cc";
import { HGeometry, ILineIndex } from "./HYXHGeometry";
import { ICartesian } from "./Cartesian"; 
import { HPolygon } from "./HYXHPolygon";
import { UNION_NUMBER_ARRAY } from "./HDataType";
import { PointsCollection } from "./HYXHPointsCollection";
import { Cartesian3 } from "./Cartesian3";

export class HCircle extends HPolygon {
        
    /**
     * 圆心点X坐标值
     */
    public center: ICartesian;
    /**
     * 半径
     */
    public radius: number;
    /**
     * 圆的图层
     */
    public static readonly RING_COUNT = 1;
    /**
     * 圆的边数
     */
    public static readonly PRE_RING_LINE_COUNT = 16;    
    // 计算圆上某点的坐标
    private getPointAtAngle(angleInDegrees: number): ICartesian {
        // 将角度转换为弧度
        const angleInRadians = (angleInDegrees * Math.PI) / 180;
        
        return {
            x: this.center.x + this.radius * Math.cos(angleInRadians),
            y: this.center.y + this.radius * Math.sin(angleInRadians),
            z: this.center.z
        };
    }

    private generateCirclePoints() {
        
        const layer = 0;        // 零层
        
        this.rings.set(layer, new PointsCollection());
        const step = 360 / HCircle.PRE_RING_LINE_COUNT; 
        /* 填充节点 */
        for (let i = 0; i <= 360; i += step) {
            this.pushBack(layer, this.getPointAtAngle(i));
        } 
    }

    constructor(center: ICartesian, radius: number) {
        super();
        this.center = center?? {x: 0.0, y: 0.0, z: 0.0} as  Cartesian3;
        this.radius = radius ?? 100.0;
        
    }
    equals(other: HGeometry): boolean {
        throw new Error("Method not implemented.");
    }
    update(): boolean {
        throw new Error("Method not implemented.");
    }
    toPointsVec3Coords(): Array<Vec3> {
        throw new Error("Method not implemented.");
    }
    toString(): string {
        throw new Error("Method not implemented.");
    }   
    
}